﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.VCCodeModel;
using System.IO;
using System.Windows;

namespace GordonKristan.codeclean
{
	class TreeViewEx : TreeView
	{
		public bool dragging;
		public int y;
		public int x1;
		public int x2;

		public TreeViewEx() : base()
		{
			dragging = false;
			y = x1 = x2 = -1;
		}

		/// <summary>
		/// Draws a line between selected nodes
		/// </summary>
		protected override void OnPaint(PaintEventArgs e)
		{
			Graphics g = e.Graphics;
			if (dragging && y >= 0 && x1 >= 0 && x2 >= 0)
			{
				Pen p = new Pen(Color.Black, 1);
				g.DrawLine(p, x1, y, x2, y);
			}
		}

		/// <summary>
		/// Forces the window to call our OnPaint even after the 
		/// TreeView paint event.
		/// </summary>
		protected override void WndProc(ref System.Windows.Forms.Message m)
		{
			base.WndProc(ref m);

			if (m.Msg == 0x000F) //WM_PAINT message
			{
				Graphics graphics = Graphics.FromHwnd(this.Handle);
				PaintEventArgs pe = new PaintEventArgs(graphics, new Rectangle(0, 0, this.Width, this.Height));
				OnPaint(pe);
			}
		}
	}
}
